package com.gushi.POICreateExcel.cellStyle;

import com.sun.xml.internal.ws.api.pipe.FiberContextSwitchInterceptor;
import org.apache.poi.hssf.record.PaletteRecord;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFPalette;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*;

import javax.swing.border.Border;

public class gsCellStyle {

    private HSSFWorkbook workbook;
    private HSSFCellStyle cellStyle;
    private HSSFFont cellFont;

    public HSSFCellStyle getCellStyle() {
        return cellStyle;
    }

    public void setCellStyle(HSSFCellStyle cellStyle) {
        this.cellStyle = cellStyle;
    }

    public gsCellStyle (HSSFWorkbook pWorkBook) {
        this.workbook = pWorkBook;
        this.cellStyle = pWorkBook.createCellStyle();
        this.cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        this.cellFont = pWorkBook.createFont();
        this.cellFont.setFontHeightInPoints((short)12);
        this.cellStyle.setFont(this.cellFont);
    }




    public gsCellStyle setLeft () {
        this.cellStyle.setAlignment(HorizontalAlignment.LEFT);
        return this;
    }

    public gsCellStyle setCenter () {
        this.cellStyle.setAlignment(HorizontalAlignment.CENTER);
        return this;
    }

    public gsCellStyle setRight () {
        this.cellStyle.setAlignment(HorizontalAlignment.RIGHT);
        return this;
    }

    public gsCellStyle setVerticalAlignment (VerticalAlignment verticalAlignment) {
        this.cellStyle.setVerticalAlignment(verticalAlignment);
        return this;
    }

    public gsCellStyle setBold () {
        this.cellFont.setBold(true);
        return this;
    }

    public gsCellStyle setBold (boolean bold) {
        this.cellFont.setBold(bold);
        return this;
    }

    public gsCellStyle setFontSize (int size) {
        this.cellFont.setFontHeightInPoints((short)size);
        return this;
    }

    public gsCellStyle setFontName (String fontName) {
        this.cellFont.setFontName(fontName);
        return this;
    }

    public gsCellStyle setBorder () {
        setBorder(BorderStyle.THIN);
        return this;
    }

    public gsCellStyle setBorder (BorderStyle borderStyle) {
        this.cellStyle.setBorderTop(borderStyle);
        this.cellStyle.setBorderBottom(borderStyle);
        this.cellStyle.setBorderLeft(borderStyle);
        this.cellStyle.setBorderRight(borderStyle);
        return this;
    }

    public gsCellStyle setBackgroundColor () {

        this.cellStyle.setFillForegroundColor(HSSFColor.MAROON.index);
        this.cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        return this;
    }
}
